Flash Article

Building a Tip of the Day Application (Part 3): Submitting Tips to the Web Service


Table of Contents

  1. Introduction
  2. Binding Data to the Submit a Tip Interface
  3. Formatting Dates
  4. Building the Calendar Browse Interface
  5. Searching for Tips
  6. Displaying a Tip from the Search Results
  7. Applying a Style Sheet

Binding Data to the Submit a Tip Interface

Adding the "submit a tip" feature is actually fairly simple because it only takes five parameters (AuthorName_txt, AuthorEmail_txt, AuthorURL_txt, TipTitle_txt and TipText_txt) and sends them to the web service. Since this web service does not return any variables, it is easy to set up because it only needs a handful of bindings and one behavior.

Create the web service for submitting tips as follows:

  1. With the presentation screen selected, open the Web Services panel (Ctrl+Shift+F10) and expand the tipService web service.
  2. Right-click the submitTip method. Select Add Method Call from the contextual menu. This adds a new instance of the WebServiceConnector component to the Stage.
  3. Drag the new WebServiceConnector instance off the Stage with the other data components and assign it an instance name of submitTip_wsc.

Bind the parameters of the tip submission web service to interface items (components) on the submit screen:

  1. In the Bindings tab of the Component Inspector panel, add five bindings (one for each of the parameters). To do this, click the Add Binding button (+) in the Component Inspector panel’s Bindings tab. In the Add Binding window, select each parameter and click OK to add the binding. When you’re done, the Bindings tab should look as it does below in Figure 1.

    Data bindings in the Component Inspector panel

    Figure 1. Data bindings in the Component Inspector panel

  2. Select the params.AuthorName binding. Double-click the Value column next to bound to in the Name/Value section below the binding listings. The Bound To dialog box opens.
  3. In the lower screen, double-click the value box to the right of bound to. In the Bound To dialog box, navigate to the submit screen and choose TextInput, <AuthorName_txt>. This sets the Component path, adding text : String to the Schema location pane. (See Figure 2.)
  4. Press OK to bind the params.AuthorName data object to its corresponding component in the submit screen.
  5. Repeat the process for AuthorEmail, AuthorURL, TipTitle and TipText, changing the component path accordingly.

    Binding params.AuthorName to the AuthorName_txt TextInput component instance on the submit screen.

    Binding params.AuthorName to the AuthorName_txt TextInput component instance on the submit screen.

    Figure 2. Binding params.AuthorName to the AuthorName_txt TextInput component instance on the submit screen.

Now, activate the submit button so it triggers the web service and redirects the user to the submitthankyou screen:

  1. Click the submit screen and select the Submit button on the Stage.
  2. In the Behaviors panel, click the Add Behavior button (+), then select Data > Trigger Data Source from the contextual menu. Select the submitTip_wsc component and click OK.

Test the application (Control-Enter). As you test, do the following:

  1. Enter a tip and press the Submit button. The web service sends an e-mail to the administrator with the data entered into the text fields.
  2. Press the "back" button on the thank you page. Notice that the values entered by the visitor remain in the text fields.

The final point can be annoying to users who want to add another tip; they probably don't want to have to delete the old tip values manually. When users click the back button, you will want to clear the existing form values for TipTitle_txt and TipText_txt. You can leave the person’s name, e-mail, and URL in the form fields because the user may reuse those values.

Here's a method for doing this as part of the on (click) script for the Back button. You could also clear the form variables using an on (reveal) on the submitthankyou screen directly if you prefer. Each way of accomplishing this task has advantages and disadvantages.

Select the Back button on the submitthankyou screen. Add the following code to the top of Actions panel, after the on (click) { as follows:

	this._parent._parent.submit.TipTitle_txt.text = "";
	this._parent._parent.submit.TipText_txt.text = "";

You can find these paths by using the Insert a target path button in the Actions panel and clicking the instance you want. Now after someone submits a tip and hits the Back button, the application clears out the values for TipTitle_txt and TipText_txt.